package com.phiyon.mytry.sharepreferences;

import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText nameEdit;
	private EditText paramEdit;
	private PreferencesService service;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		nameEdit  = (EditText) this.findViewById(R.id.editName);
		paramEdit = (EditText) this.findViewById(R.id.editParam);
		service = new PreferencesService(this);
		Map<String, String> params = service.getPreferences();
		nameEdit.setText(params.get("name"));
		paramEdit.setText(params.get("param"));
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void save(View v){
		String name = nameEdit.getText().toString();
		String param = paramEdit.getText().toString();
		
		service.save(name, Integer.valueOf(param));
		Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
	}
	

}
